package com.my.sender;

import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

/**
 * 消息发送者
 */
@Component
public class ProductSender {

    private AmqpTemplate rabbitAmqpTemplate;

    @Autowired
    public void setRabbitAmqpTemplate(AmqpTemplate rabbitAmqpTemplate) {
        this.rabbitAmqpTemplate = rabbitAmqpTemplate;
    }

    //交换器名称
    @Value("${mq.config.email.exchange}")
    private String emailExchange;
    //路由键
    @Value("${mq.config.queue.email.push}")
    private String emailRoutingKey;

    @Value(("${mq.config.queue.phone.push}"))
    private String phoneRoutingKey;

    @Value("${mq.config.phone.exchange}")
    private String phoneExchange;

    /**
     * 发送消息的方法
     */
    public void sendEmail(String email) {
//        System.out.println(emailRoutingKey);
        rabbitAmqpTemplate.convertAndSend(emailExchange, emailRoutingKey, email);
    }

    public void sendPhone(String phone) {
//        System.out.println(phoneRoutingKey);
        rabbitAmqpTemplate.convertAndSend(phoneExchange, phoneRoutingKey, phone);
    }


}
